<template>
  <div style="display: inline-block">
    <el-button type="danger" @click="cancelWork" :loading="loading">{{$t('middle.重新入库')}}</el-button>
    <el-dialog
      :title="$t('middle.确认当前商品已重新入库？')"
      :visible.sync="dialog"
      width="500px"
      :modal-append-to-body="false"
    >
      <div style="margin-top: -20px">
        <span>{{$t('middle.当前送仓工单用户已撤销，请操作重新入库并确认是否退回本次中转和贴标费用')}}</span>
        <div class="mgt20 return-content">
          <div class="label font-red">
            {{ $t('middle.送仓费用(N)元',{money: currentForm.transfer2warehouse}) }}:
            <el-button class="mgl10" :type="!currentForm.isReturnTransfer ? 'primary' : ''" @click="currentForm.isReturnTransfer = false">{{ $t('order.Do not return') }}</el-button>
            <el-button :type="currentForm.isReturnTransfer ? 'primary' : ''" @click="currentForm.isReturnTransfer = true">{{ $t('order.return') }}</el-button>
          </div>
          <div class="label font-red mgt10" v-if="currentForm.charteredCarFee">
            {{ $t('middle.包车费用(N)元',{money: currentForm.charteredCarFee}) }}:
            <el-button class="mgl10" :type="!currentForm.isReturnCarFee ? 'primary' : ''" @click="currentForm.isReturnCarFee = false">{{ $t('order.Do not return') }}</el-button>
            <el-button :type="currentForm.isReturnCarFee ? 'primary' : '' " @click="currentForm.isReturnCarFee = true">{{ $t('order.return') }}</el-button>
          </div>
          <div class="label font-red mgt10" v-if="currentForm.labelFee">
            {{ $t('middle.贴SKU标费用(N)元',{money: currentForm.labelFee}) }}:
            <el-button class="mgl10" :type="!currentForm.isReturnLabel ? 'primary' : ''" @click="currentForm.isReturnLabel = false">{{ $t('order.Do not return') }}</el-button>
            <el-button :type="currentForm.isReturnLabel ? 'primary' : '' " @click="currentForm.isReturnLabel = true">{{ $t('order.return') }}</el-button>
          </div>
          <div class="label font-red mgt10" v-if="currentForm.boxLabelFee">
            {{ $t('middle.贴外箱标费用(N)元',{money: currentForm.boxLabelFee}) }}:
            <el-button class="mgl10" :type="!currentForm.isReturnBox ? 'primary' : ''" @click="currentForm.isReturnBox = false">{{ $t('order.Do not return') }}</el-button>
            <el-button :type="currentForm.isReturnBox ? 'primary' : '' " @click="currentForm.isReturnBox = true">{{ $t('order.return') }}</el-button>
          </div>

        </div>
      </div>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialog = false">{{ $t('common.cancel') }}</el-button>
        <el-button type="primary" @click="submitCancel" :loading="loading">{{ $t('common.confirm') }}</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import {knowCancel} from "@/api/middleWork";

export default {
  name: "CancelButton",
  props:{
    middle: {
      type: Object,
      required: true,
      default: function(){
        return {};
      }
    }
  },
  data(){
    return {
      loading: false,
      dialog: false,
      currentForm: {
        id: 0,
        transfer2warehouse: 0, // 中转送仓费
        labelFee: 0, // 贴标费
        boxLabelFee: 0, // 箱标费用
        charteredCarFee: 0, // 包车费
        isReturnTransfer: false, // 是否退中转费
        isReturnLabel: false, // 是否退贴标费用
        isReturnBox: false, // 是否退回箱标费用
        isReturnCarFee: false, // 是否退回包车费用
      },
    }
  },
  methods:{
    cancelWork(){
      this.dialog = true
      this.currentForm.id = this.middle.id
      this.currentForm.transfer2warehouse = Number(this.middle.transfer2warehouse)
      this.currentForm.boxLabelFee = Number(this.middle.boxLabelFee)
      this.currentForm.labelFee = this.middle.labelOrder ? this.middle.labelOrder.rlTotalLabelFee : 0;
      this.currentForm.labelFee = Number(this.currentForm.labelFee)
      this.currentForm.charteredCarFee = Number(this.middle.charteredCarFee)
      this.currentForm.isReturnTransfer = false
      this.currentForm.isReturnLabel = false
      this.currentForm.isReturnBox = false
      this.currentForm.isReturnCarFee = false
    },
    submitCancel(){
      this.loading = true
      knowCancel(this.currentForm)
        .then(res=>{
          this.loading = false
          if(res.error === 0){
            this.dialog = false
            this.$successMessage(res.message)
            this.$emit('finishCancel')
          }else{
            this.$errorMessage(res.message)
          }
        })
    }

  },
}
</script>

<style scoped>

</style>
